// Copyright 2013 Stephane SOPPERA
//
// This file is part of cgi-to-fastcgi.
//
// cgi-to-fastcgi is free software: you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// cgi-to-fastcgi is distributed in the hope that it will be
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with cgi-to-fastcgi.  If not, see <http://www.gnu.org/licenses/>.
package main

import (
	"fmt"
	"net/http"
	"net/http/cgi"
	"os"
)

func main() {
	// setup a handler function for all paths that simply writes back
	// some debug informations (not taking into account the method)
	http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
		w.Header().Set("Content-Type", "text/plain; charset=UTF-8")
		w.WriteHeader(http.StatusOK)
		fmt.Fprintf(w, "Req :\r\n  %+v\r\n\r\n", *req)
		fmt.Fprintf(w, "Args:\r\n  %v\r\n\r\n", os.Args)
		fmt.Fprintf(w, "Env :\r\n  %v\r\n\r\n", os.Environ())
		cwd, _ := os.Getwd()
		fmt.Fprintf(w, "Cwd :\r\n  %v\r\n\r\n", cwd)
	})

	// serve the request
	cgi.Serve(nil)
}
